package com.asgard.keybox;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

/**
 * 该类描述密钥库和相关的密钥、证书数据。
 */
@XmlRootElement(name = "KeyBox")
public class KeyBoxData {

    /**
     * 盐，Hex格式
     */
    private String salt;
    /**
     * 密钥列表
     */
    private List<ECKeyData> keys = new ArrayList<>();
    /**
     * 证书列表
     */
    private List<CertificateData> certificates = new ArrayList<>();

    @XmlElement(name = "Salt")
    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    @XmlElement(name = "ECKey")
    public List<ECKeyData> getKeys() {
        return keys;
    }

    public void setKeys(List<ECKeyData> keys) {
        this.keys = keys;
    }

    @XmlElement(name = "Certificate")
    public List<CertificateData> getCertificates() {
        return certificates;
    }

    public void setCertificates(List<CertificateData> certificates) {
        this.certificates = certificates;
    }

    /**
     * 该类描述密钥数据。
     */
    @XmlRootElement(name = "ECKey")
    public static class ECKeyData {

        /**
         * 密钥名称
         */
        private String name;
        /**
         * 私钥
         */
        private String privateKey;
        /**
         * 公钥
         */
        private String publicKey;

        @XmlAttribute(name = "name")
        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @XmlElement(name = "PrivateKey")
        public String getPrivateKey() {
            return privateKey;
        }

        public void setPrivateKey(String privateKey) {
            this.privateKey = privateKey;
        }

        @XmlElement(name = "PublicKey")
        public String getPublicKey() {
            return publicKey;
        }

        public void setPublicKey(String publicKey) {
            this.publicKey = publicKey;
        }

        @Override
        public String toString() {
            return "ECKey { name = " + name + ", privateKey = " + privateKey + ", publicKey = " + publicKey + " }";
        }
    }

    /**
     * 该类描述证书数据。
     */
    @XmlRootElement(name = "Certificate")
    public static class CertificateData {

        /**
         * 证书名称
         */
        private String name;
        /**
         * 私钥
         */
        private String privateKey;
        /**
         * Hex格式的证书内容
         */
        private String content;

        @XmlAttribute(name = "name")
        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @XmlElement(name = "PrivateKey")
        public String getPrivateKey() {
            return privateKey;
        }

        public void setPrivateKey(String privateKey) {
            this.privateKey = privateKey;
        }

        @XmlElement(name = "Content")
        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        @Override
        public String toString() {
            return "Certificate { privateKey = " + privateKey + ", content = " + content + " }";
        }
    }

}
